package com.isunland.managesystem.ui;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.NavUtils;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import com.isunland.managesystem.R;
import com.isunland.managesystem.base.BaseVolleyActivity;
import com.isunland.managesystem.utils.LogUtil;

public class AttendanceDetailBigPhotoFragment extends Fragment {

  public static final String FILE_DIR = "com.isunland.managesystem.ui.FILE_DIR";
  private static final String TAG = AttendanceDetailBigPhotoFragment.class.getName();
  private ImageView mBigPhotoAttendanceDetail;

  @Override public void onCreate(Bundle savedInstanceState) {
    setHasOptionsMenu(true);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
      if (NavUtils.getParentActivityName(getActivity()) != null) {

        ((BaseVolleyActivity) getActivity()).getSupportActionBar().setDisplayHomeAsUpEnabled(true);
      }
    }

    ((BaseVolleyActivity) getActivity()).getSupportActionBar().hide();
    super.onCreate(savedInstanceState);
  }

  @Override public View onCreateView(LayoutInflater inflater, ViewGroup container,
      Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_bigphoto_attendance, container, false);
    mBigPhotoAttendanceDetail = (ImageView) view.findViewById(R.id.iv_bigPhoto_attendanceDetail);

    initPhoto();

    return view;
  }

  private void initPhoto() {
    String fileDir = getArguments().getString(FILE_DIR);
    LogUtil.i(TAG, "fileDir^^^^^^^" + fileDir);
    Bitmap bitmap = BitmapFactory.decodeFile(fileDir);

    mBigPhotoAttendanceDetail.setImageBitmap(bitmap);
  }

  @Override public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
      case android.R.id.home:

        if (NavUtils.getParentActivityName(getActivity()) != null) {
          NavUtils.navigateUpFromSameTask(getActivity());
        }
        break;

      default:
        break;
    }
    return super.onOptionsItemSelected(item);
  }

  public static Fragment newInstance(String filePatn) {
    Bundle bundle = new Bundle();
    bundle.putString(FILE_DIR, filePatn);
    AttendanceDetailBigPhotoFragment fragment = new AttendanceDetailBigPhotoFragment();
    fragment.setArguments(bundle);
    return fragment;
  }
}
